#!/usr/bin/python
#
# Copyright 2011 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""GIT login page flow.

Defines the GIT login page flow in Google AppEngine.
You can write your own login page yourself for your platform based on Git
library.
"""

__author__ = 'Xin Zhou(zhounew@google.com)'

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.dist import use_library
use_library('django', '1.2')

from git.handler import git_login_handler

class MainPage(webapp.RequestHandler):
  def post(self):
    arguments = self.request.arguments()
    
    if 'rp_target' not in arguments:
      action = ''
    else:
      action = self.request.get('rp_target')
    
    if 'email' not in arguments:
      email = ''
    else:
      email = self.request.get('email')
    
    if 'password' not in arguments:
      password = ''
    else:
      password = self.request.get('password')
    
    handler = git_login_handler.GitLoginHandler(action, email, password)
    self.response.out.write(handler.Execute())

application = webapp.WSGIApplication([('/gitlogin.do', MainPage)], debug=False)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()